package com.cmcc.passenger.ui.onorder

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.passenger.data.AppRequest
import com.cmcc.passenger.data.PassDataRepository
import com.cmcc.passenger.data.entity.response.CarCategory
import com.cmcc.passenger.data.entity.response.NearbyCar
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class CarNearbyViewModel : ViewModel() {

    val nearbyCar = MutableLiveData<List<NearbyCar>>()

    /**
     * 获取附近司机
     */
    fun getNearbyDriver(lat: Double?, lng: Double?) {
        if (lat != null && lng != null)
            viewModelScope.launch(Dispatchers.Main) {
                try {
                    val response = AppRequest.getInstance().nearbyCar(lat, lng)
                    if (response.isSuccessful) {
                        val data = response.body()
                        nearbyCar.value = data?.data
                    }
                } catch (e: Exception) {
                    L.d("e :" + e.message + "," + e.cause)
                }
            }
    }


}